/*
 *  levelUpGame - Player.h
 *  Copyright 2011 W. Reckman. All rights reserved.
 */
#ifndef PLAYER_H
#define PLAYER_H

#include <string>
#include "ofxTimer.h"
#include "ofTypes.h"
#include "ofImage.h"
#include "GameEventHandler.h"
#include "BalanceMeter.h"
#include "GameModel.h"
#include "GridObject.h"

using std::string;

class LevelUpApp;
class EventArgs;

//NOTE: comment this define if players should only mirror while moving
#define ROTATE_PLAYERS

//NOTE: uncomment to draw circles behind players in their respective colors
//#define DRAW_PLAYER_CIRCLES

class Player : public GridObject {
public:
	static const float MAX_BITE_ANGLE;
	static const float BLINK_DELAY_SECONDS;
	static const float BLINK_MIN_OPACITY;
	static const float PLAYER_WIN_DRAW_SCALE;
	
	
	explicit Player( const LevelUpApp& appRef_ );
	~Player();
	
	void setup( const GameModel::PlayerInfo& info_ );
	void update();
	void drawAtPos( int x_, int y_, float animPos_ = 0.0f, float scale_ = 1.0f ) const;
	void draw( bool drawAsWinner_ = false, float animPos_ = 0.0f ) const;
	
	int getId() const;
	const ofColor& getColor() const;
	int getStartingLane() const;
	const BalanceMeter& getCurrentBalance() const;
	const BalanceMeter& getTargetBalance() const;
	const GameModel::PlayerInfo& getInfo() const;
	
	void setStartingLane( int startingLane_ );
	void addBalance( int val_, BALANCE_KIND kind_ );
	void resetPosition();
	
	void incrementGoodPickupCount();
	void incrementBadPickupCount();
	
	void startFreezeTimeout( float seconds_ );
	void startNonCorporealTimeout( float seconds_ );
	
	void onUnfreezeEvent( ofEventArgs& ev_ );
	void onCorporealizeEvent( ofEventArgs& ev_ );
	
private:
	//prohibit copying
	explicit Player( const Player& other_ );
	const Player& operator=( const Player& other_ );
	
	ofxTimer unfreezeTimer, corporealizeTimer;
	
	const LevelUpApp& appRef;
	const GameModel& game;
	
	GameModel::PlayerInfo info;
	ofImage* topImage;
	ofImage* bottomImage;
	bool drawMirrored;
	float drawRotated;
	int biteSpeed;
	int startingLane;
	BalanceMeter targetBalance, currentBalance;
	
	float lastGameTime;
	bool biteAngleIncreasing;
	float biteAngle;
	
	float lastBlinkTime;
	float drawAlpha;
	
	void draw( int x_, int y_, float rotation_, float scale_ = 1.0f ) const;
};

#endif /* ! PLAYER_H */
